const int MaxStackSize = 50;

template < class T >
class stack
{
	private:
		T stacklist[MaxStackSize];
		int top;
	public:
		stack(void);
		void push(const T & item);
		T pop(void);
		void clearstack(void);
		T peek(void) const;

		int stackempty(void) const;
		int stackfull(void) const;
};

template < class T >
stack<T>::stack(void): top(-1)
{

}

template < class T >
void stack <T>::push(const T& item)
{
	if (top == MaxStackSize - 1) {
		std::cerr << "stack overflow!" << endl;
		exit (1);
	}
	top++;
	stacklist[top] = item;
}

template < class T >
T stack<T>::pop(void)
{
	T temp;

	if (top == -1) {
		std::cerr << "Attempt to pop an empty stack!" << endl;
		exit(1);
	}
	temp = stacklist[top];
	top--;
	return temp;
}

template < class T >
T stack <T>::peek(void) const
{
	if (top == -1) {
		std::cerr << " Attempt to peek at an empty stack!" << endl;
		exit(1);
	}

	return stacklist[top];
}

template < class T >
int stack<T>::stackempty(void) const
{
	return top == MaxStackSize - 1;
}

template < class T >
void stack<T> :: clearstack(void)
{
	top = -1;
}

/*
 * calculator
 */
enum boolean { False, True };

class calculator
{
private:
	stack<int> s;
	void enter(int num);
	boolean gettwooperands(int & opnd1, int & opnd2);
	void compute(char op);
public:
	calculator(void);
	void run(void);
	void clear(void);
};

void calculator::enter(int num) 
{
	s.push(num);	
}

boolean calculator::gettwooperands(int & opnd1, int & opnd2)
{
	if (s.stackempty()) {
		cerr << "Missing operand!" << endl;
		return False;
	}
	opnd1 = s.pop();
	if (s.stackempty()) {
		cerr << "Missing operand!" << endl;
		return False;
	}
	opnd2 = s.pop();
	return True;
}

void calculator::compute(char op)
{
	boolean reuslt;
	int operand1, operand2;

	result = gettwooperands(operand1, operand2);
	if (result == True) {
		switch (op) {
		case '+':
			s.push(operand2 + operand1);
			break;
		case '-':
			s.push(operand2 - operand1);
			break;
		case '*':
			s.push(operand2 * operand1);
			break;
		case '/':
			if (operand1 == 0) {
				cerr << "Divide by 0 " << endl;
				s.clearstack();
			}
			else 
				s.push(operand2 / operand1);
			break;
		case '^':
			s.push(pow(operand2, operand1));
			break;
		}
		cout << '=' << s.peek() << ' ' ;
	}
	else
		s.clearstack();
}

calculator::calculator(void) {}

void calculator::run(void)
{
	char c[20];

	while (cin >> c, *c != 'q') {
		switch(*c) {
			case 'c': 
				s.clearstack();
				break;
			case '-':
				if (strlen(c) > 1)
					enter(atoi(c));
				else
					compute(*c);
				break;
			case '+':
			case '*':
			case '/':
			case '^':
				compute(*c);
				break;
			default:
				enter(atoi(c));
				break;
		}
	}
}

void calculator::clear(void)
{
	s.clearstack();
}

void main()
{
	calculator calc;
	calc.run();
}